/*
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($, e, b) {
	var c = "hashchange",
	h = document,
	f, g = $.event.special,
	i = h.documentMode,
	d = "on" + c in e && (i === b || i > 7);
	function a(j) {
		j = j || location.href;
		return "#" + j.replace(/^[^#]*#?(.*)$/, "$1")
	}
	$.fn[c] = function(j) {
		return j ? this.bind(c, j) : this.trigger(c)
	};
	$.fn[c].delay = 50;
	g[c] = $.extend(g[c], {
		setup: function() {
			if (d) {
				return false
			}
			$(f.start)
		},
		teardown: function() {
			if (d) {
				return false
			}
			$(f.stop)
		}
	});
	f = (function() {
		var j = {},
		p, m = a(),
		k = function(q) {
			return q
		},
		l = k,
		o = k;
		j.start = function() {
			p || n()
		};
		j.stop = function() {
			p && clearTimeout(p);
			p = b
		};
		function n() {
			var r = a(),
			q = o(m);
			if (r !== m) {
				l(m = r, q);
				$(e).trigger(c)
			} else {
				if (q !== m) {
					location.href = location.href.replace(/#.*/, "") + q
				}
			}
			p = setTimeout(n, $.fn[c].delay)
		}
		$.browser.msie && !d && (function() {
			var q, r;
			j.start = function() {
				if (!q) {
					r = $.fn[c].src;
					r = r && r + a();
					q = $('<iframe tabindex="-1" title="empty"/>').hide().one("load",
					function() {
						r || l(a());
						n()
					}).attr("src", r || "javascript:0").insertAfter("body")[0].contentWindow;
					h.onpropertychange = function() {
						try {
							if (event.propertyName === "title") {
								q.document.title = h.title
							}
						} catch(s) {}
					}
				}
			};
			j.stop = k;
			o = function() {
				return a(q.location.href)
			};
			l = function(v, s) {
				var u = q.document,
				t = $.fn[c].domain;
				if (v !== s) {
					u.title = h.title;
					u.open();
					t && u.write('<script>document.domain="' + t + '"<\/script>');
					u.close();
					q.location.hash = v
				}
			}
		})();
		return j
	})()
})(jQuery, this);

var last_mod = "";
var mod_title = [];
window.msg_mode = false;
if (typeof(window.ajaxQuery) != "undefined" && typeof(window.ajaxQuery.abort) == "function") window.ajaxQuery.abort();
window.ajaxQuery = undefined;
$(function() {
	$(window).hashchange(function() {
		if (!location.hash || location.hash == "#") {
			location.hash = "main";
			return;
		}
		if (location.hash && location.hash != "#" && location.hash.substr(1) != last_mod) {
			last_mod = location.hash.substr(1);
			var mod_id = location.hash.match(/^#([a-z0-9A-Z_]+)/);
			$("#content").fadeOut(200);
			$(".aside > li > a").removeClass();
			$("#btn_" + mod_id[1]).addClass("on"); 
			document.title = mod_title[mod_id[1]] + " - 会员中心 - 哔哩哔哩";
			var webURl = location.href.replace(/#.*/, "");
			if (typeof(window.ajaxQuery) != "undefined" && typeof(window.ajaxQuery.abort) == "function") window.ajaxQuery.abort();
			window.ajaxQuery = $.ajax({
				url: webURl + "data.php" + "?ajax=1&mod=" + last_mod + "&r=" + Math.random(),
				success: function(data) {
					$("#content").hide();
					$("#content").removeClass();
					$("#content").html(data);
					$("#content").fadeIn(200);
				},
				error: function(msg) {
					last_mod = "";
					$("#content").hide();
					$("#content").removeClass();
					$("#content").addClass("error");
					$("#content").html("");
					$("#content").fadeIn(200);
				}
			});
		}
	});

	var btns = $(".aside > li > a");
	for (var i = 0; i < btns.length; i++) {
		if (btns[i].id.match(/^btn_/)) {
			mod_title[btns[i].id.substr(4)] = btns[i].title;
			btns[i].href = "#" + btns[i].id.substr(4);
		}
	}

	if (!window.msg_mode) {
		$(window).hashchange();
	} else {
		$(".aside > li > a").removeClass();
		$("#btn_" + window.current_mod).addClass("on");
	}
});

function sendpm(pm, title) {
	$('.pmdiv').fadeIn(500);
	$('#pm_id').val(pm);
	if (title) {
		$('#pm_title').val(title);
		$('#pm_msg').focus();
	} else {
		$('#pm_title').focus();
	}
	return false;
}
function bangumi(){
	$("#btn_normal").removeClass("on");
	$("#btn_bangumi").addClass("on");
	$("#bangumi_person_layer").show();
	$("#bangumi_area_layer").show();
	$("#bangumi_version_layer").show();
	$("#bangumi_style_layer").show();
	$("#bangumi_date_layer").show();
	$("#is_bangumi").val(1)
	$("#bangumi_date").datepicker();
}
function showpmmsg(pmid) {
	if ($("#msg-txt-" + pmid).css("display") == "block") return false;
	$("#msg-txt-" + pmid).html("<img src=\"http://static.hdslb.com/images/common/wait.gif\" style=\"width:48px;height:47px\"/>");
	$("#msg-txt-" + pmid).css("display", "block");
	$.ajax({
		url: "/member?mod=msg&act=showmsg&pmid=" + pmid,
		success: function(msg) {
			$("#msg-txt-" + pmid).html(msg);
		},
		failure: function() {
			$("#msg-txt-" + pmid).html("ERROR");
		}
	});
	return false;
}

function submitTheForm(formid) {
	var $form = $('#' + formid);
	url = $form.attr('action');
	var i = $.post(url, $form.serialize(),
	function(data) {
		alert(data);
	});
}
function ajaxgetdata(urlx) {
	$.get(urlx,
	function(result) {
		if (result.indexOf("成功") != -1) {} else {
			aleat("操作失败");
		}
	});
}